package com.zzy.config;

import java.sql.*;
import java.util.Properties;

public class DBConfig {
    private static Properties properties = new Properties();;
    private static Connection conn;

    static {
            try {
                properties.load(DBConfig.class.getClassLoader().getResourceAsStream("com/zzy/config/db.properties"));
                Class.forName(properties.getProperty("driver"));
                String url = properties.getProperty("url");
                String username = properties.getProperty("username");
                String password = properties.getProperty("password");
                conn = DriverManager.getConnection(url, username, password);
                System.out.println("=============驱动加载成功==============");

            } catch (Exception classNotFoundException) {
                classNotFoundException.printStackTrace();
            }
    }

    public PreparedStatement getPS(String sql) throws SQLException {
        return conn.prepareStatement(sql);
    }

    public Statement getStmt() throws SQLException {
        return conn.createStatement();
    }
}
